#include "landblock.h"

LandBlock::LandBlock()
{
    initialize();
}

LandBlock::LandBlock(QWidget *parent)
    :QWidget(parent)
{
    initialize();
}

LandBlock::LandBlock(bool hasLandMine, QWidget *parent) : QWidget(parent),
    hasLandMine(hasLandMine)
{
    initialize();
}

LandBlock::LandBlock(Pos *blockPos, QWidget *parent) : QWidget(parent),
    blockPos(blockPos)
{
    initialize();
}

LandBlock::LandBlock(bool hasLandMine, Pos *blockPos, QWidget *parent) : QWidget(parent),
    hasLandMine(hasLandMine),
    blockPos(blockPos)
{
    initialize();
}

void LandBlock::initialize()
{
    connect(mask, &QPushButton::clicked, this, &LandBlock::searchBlock);
    connect(this, &LandBlock::isSearchChanged, this, &LandBlock::searchBlock);
    connect(this, &LandBlock::hasLandMineChanged, this, &LandBlock::placeLandMine);
    placeLandMine();
    mask->show();
    content->hide();
}

LandBlockMask *LandBlock::getMask() const
{
    return mask;
}

void LandBlock::setMask(LandBlockMask *newMask)
{
    if (mask == newMask)
        return;
    mask = newMask;
    emit maskChanged();
}

LandBlockContent *LandBlock::getContent() const
{
    return content;
}

void LandBlock::setContent(LandBlockContent *newContent)
{
    if (content == newContent)
        return;
    content = newContent;
    emit contentChanged();
}

bool LandBlock::getIsSearch() const
{
    return isSearch;
}

void LandBlock::setIsSearch(bool newIsSearch)
{
    if (isSearch == newIsSearch)
        return;
    isSearch = newIsSearch;
    emit isSearchChanged();
}

void LandBlock::searchBlock()
{
    setIsSearch(true);
    mask->hide();
    content->show();
}

void LandBlock::placeLandMine()
{
    if (hasLandMine == true) content->setPalette(QPalette(Qt::red));
    else content->setPalette(QPalette(Qt::white));
}

Pos *LandBlock::getBlockPos() const
{
    return blockPos;
}

void LandBlock::setBlockPos(Pos *newBlockPos)
{
    if (blockPos == newBlockPos)
        return;
    blockPos = newBlockPos;
    emit blockPosChanged();
}

void LandBlock::resetBlockPos()
{
    setBlockPos({}); // TODO: Adapt to use your actual default value
}

void LandBlock::resetMask()
{
    setMask({}); // TODO: Adapt to use your actual default value
}

void LandBlock::resetContent()
{
    setContent({}); // TODO: Adapt to use your actual default value
}

void LandBlock::resetIsSearch()
{
    setIsSearch({}); // TODO: Adapt to use your actual default value
}

void LandBlock::resetHasLandMine()
{
    setHasLandMine({}); // TODO: Adapt to use your actual default value
}

bool LandBlock::getHasLandMine() const
{
    return hasLandMine;
}

void LandBlock::setHasLandMine(bool newHasLandMine)
{
    if (hasLandMine == newHasLandMine)
        return;
    hasLandMine = newHasLandMine;
    emit hasLandMineChanged();
}
